from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect

from records.models import Record
from records.models import Game

from django.contrib import admin

class RecordInline(admin.TabularInline):
	model = Record
	#extra = 100
	can_delete = True

csrf_protect_m = method_decorator(csrf_protect)
	
class GameAdmin(admin.ModelAdmin):
	change_form_template = 'records/records_change_form.html'
#	fieldsets = [
#				(None, 			{'fields':['name']}), 
#				('Date', 		{'fields':['date']}),
#				('Location', 	{'fields':['location']}),
#				]
	fields = ('type', 'name', 'dateTime', 'country', 'county', 'field', 'temperature', 'humidity', 'windSpeed', 'umpires')
	save_on_top = True
	inlines = [RecordInline]
	list_display = ('type', 'name', 'dateTime', 'country', 'county', 'field')
	list_filter = ['dateTime', 'type', 'country', 'county', 'field']

#	@csrf_protect_m
#	@transaction.commit_on_success
#	def add_view(self, request, form_url='', extra_context=None):
#		# no custom POST process to parse csv file on the server side
#		return super(GameAdmin, self).add_view(request, form_url, extra_context)

admin.site.register(Game, GameAdmin)
